# -*- coding: utf-8 -*-

'''
Created on 26/11/2011

@author: Luis M. Ugalde
www.forondarena.net

Copyright © 2011 Luis M. Ugalde
Licensed under the terms of the MIT License
(see LICENSE file for details)

This software can't be considered to be even in Alpha state. It still needs a lot of work.
'''


import sys
from readers.readerexception import ReaderException


class Reader(object):
    '''
    Reader facade-like structural pattern.
    '''


    def __init__(self, readertype, availablereaders, *args, **kwargs):
        '''
        self.availableclasses = {'ReaderFile': rdfile.ReaderFile ,
                        'ReaderZeroMQ': rdzeromq.ReaderZeroMQ,
                        'ReaderTail': rdtail.ReaderTail
                        }
        '''
        
        self.availableclasses = availablereaders
        
        try:
            module, klass = self.availableclasses[readertype].split(".")
            _tmpmodule = __import__(module, globals(), locals(), [], 1)
            self.reader = getattr(sys.modules['readers.' + module], klass)(*args, **kwargs)
        except TypeError:
            raise ReaderException('AbstractReader interface must be fully implemented')
        except KeyError:
            raise ReaderException('Reader type is not valid')
        except ImportError:
            raise ReaderException('Cant import required module')


    def setSource(self, *args, **kwargs):
        '''
        '''
        self.reader.setSource(*args, **kwargs)


    def connectSources(self, *args, **kwargs):
        '''
        '''
        self.reader.connectSources(*args, **kwargs)

        
    def setBindReader(self, *args, **kwargs):
        '''
        '''
        self.reader.setBindReader(*args, **kwargs)


    def bindReader(self, *args, **kwargs):
        '''
        '''
        self.reader.bindReader(*args, **kwargs)


    def setBindNotifyReader(self, *args, **kwargs):
        '''
        '''
        self.reader.setBindNotifyReader(*args, **kwargs)


    def bindNotifyReader(self, *args, **kwargs):
        '''
        '''
        self.reader.bindNotifyReader(*args, **kwargs)


    def getLines(self, *args, **kwargs):
        '''
        '''
        self.reader.getLines(*args, **kwargs)


if __name__ == '__main__':
    print "Please, do not run this"
